<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="shortcut icon" href="../../favicon.ico" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="../../css/reset.css" />
    <link rel="stylesheet" type="text/css" href="../../css/login.css" />
</head>

<body>
    <div class="pos">
        <div class="login">
            <span class="close iconfont icon-close"></span>
            <img src="../../img/login/loginlogo.png" alt="">
            <ul>
                <li></li>
                <li class="phone">使用手机号登陆</li>
                <li></li>
            </ul>
            <!-- <form action="" id="form"> -->
            <input style="margin-top: 0;" type="text" name="username" class="tel" placeholder="请输入您的手机号">
            <input type="password" name="password" class="pass" placeholder="请输入密码">
            <span class="tips"></span>
            <button class="loginbtn">
                登陆
            </button>
            <!-- </form> -->
            <p>
                <span>
                    还没有账号?
                    <a href="javascript:;">点击注册</a>
                </span>
            </p>
        </div>
    </div>

    <script src="../../common/jquery.min.js"></script>
    <script src="../../common/myajax.js"></script>

    <script>
        $('.loginbtn').click(async function(){
            let username=$('.tel').val()
            let password=$('.pass').val()
            if(!username||!password){
                $('.tips').html('用户名密码不能为空')
                return
            }
            let [,result]=await myAjax({
                url:'api/login',
                type:'post',
                data:{
                    username,
                    password
                }
            })
            console.log(result)
            if(result.code==200){
                //登录成功 将res返回的token存储到本地
                //清空tips
                //跳转页面或者刷新页面
                localStorage.setItem('token',result.token)
                $('.tips').html('')
                location.href='../userSeting.html'
                return
            }
            $('.tips').html(result.msg)
        })
    </script>
</body>
</html>